package flexo.physic.force;

import flexo.math.Vector;
import flexo.physic.entity.Entity;
import flexo.scene.Node;

public class Bungee extends Spring
{

	public Bungee(String name, Node hook, float length)
	{
		super(name, hook, length);
	}
	
	@Override
	public Vector calculateForce(Entity e, float deltaTime)
	{
		// Vector from the hook to the entity
		Vector.sub(e.getPosition(), hook.getAbsolutePosition(), force);
		float mag = force.getLength();
		
		force.normalize();
		mag = mag - length;
		if (mag > 0)
		{
			// k is already negated in the constructor
			force.scale( (k * (mag - length)) );
		}
		else
		{
			force.reset();
		}
		
		return force;
	}
}
